package cn.skyquant.quant4j.task.boot.task;

import cn.skyquant.quant4j.api.account.AccountService;
import cn.skyquant.quant4j.sdk.enums.Status;
import cn.skyquant.quant4j.task.boot.bo.AccountBO;
import cn.skyquant.quant4j.task.boot.entity.Account;
import cn.skyquant.quant4j.task.boot.repository.AccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/account")
@Component
public class AccountTask {

    @Autowired
    AccountBO accountBO;

    @Autowired
    AccountRepository accountRepository;

    @Autowired
    AccountService accountService;

    @Scheduled(cron = "0 0 8 ? * 1-5")
    public void daily(){
        accountBO.daily();
    }


    //每月3日的12点
    @Scheduled(cron = "0 0 12 4 * ?")
    @RequestMapping(value = "/sms",method = RequestMethod.GET)
    public void smsNotice(){
        List<Account> accountList = accountRepository.findAll();
        accountList.stream()
                .filter(x->x.notice == Status.A)
                .forEach(x->accountService.notice(x.id));
    }

}
